<template>
	<view class="product">
		<view class="box" v-for="(item,index) in list" :key="index"  @click="togoodsinfo(item)"
		:style="{'background':index==0&&logo==true?'#fff8f7':index==1&&logo==true?'#fbfaff':''}">
			<view class="product_img">
				<image mode="aspectFill" :src="loading==true?'../static/load.png':getImage(item.img)" @load="load()"></image>
				<!-- <image src="../static/logo.png"></image> -->
				<view v-if="item.is_points_gift == 1" style="position: absolute;right: 10rpx;top: 10rpx;padding: 4rpx 10rpx;background-color: #f09a73;color: white;border-radius: 10rpx;font-size: 24rpx;">送积分</view>
				<view class="imgtit">
					<image mode="aspectFill" :src="loading==true?'../static/load.png':item.avator" @load="load()"></image>
					<view class="namebox">老师:{{item.teacher_name}}</view>
				</view>
				<!-- <image :src="loading==true?'../static/load.png':item.img" @load="load()"></image> -->
			</view>
			<view class="info">
				<view class="title">{{item.course_name}}</view>
				<view class="price">
					<view class="x_price">报名截止时间</view>
					<view class="y_price">共{{item.class_hour}}课时</view>
				</view>
				<view class="text" v-if="item.course_time">上课时间:每周{{ week[item.time_arr[0].week] }} {{getTime(item.time_arr[0].start_day)}} 至 {{getTime(item.time_arr[0].end_day)}}</view>
				<view class="text">社区: {{item.community_name}}</view>
				<view class="but">
					{{item.score_price==0&&item.price==0?'免费':'教材教具费'+Number(item.price)+'元'}}
					<text v-if="item.score_price!==0">{{"+"+item.score_price+'积分'}}</text>
				</view>
			</view>
		</view>
	</view>
	
</template>

<script>
	export default {
		name: "product",
		props:{
			list:{
				type:Array,
				default:[]
			},
			logo:{
				type:Boolean,
				default:false
			}
		},
		data() {
			return {
				loading:true,
				week:['日','一', '二', '三', '四', '五', '六','日']
			};
		},
		methods:{
			getImage(url){
				if(!url)return
				if(url && url.indexOf(',')==-1){
					return url
				}else{
					return url.split(',')[0]	
				}
			},
			togoodsinfo(item){
				this.$emit('togoodsinfo',item)
			},
			load(){
				// console.log('加载')
				this.loading = false
			},
			getTime(time) {
				let date = new Date(time * 1000)
				let year = date.getFullYear()
				let month = date.getMonth() + 1
				let day = date.getDate()
				// 时分秒
				let hour = date.getHours()>9?date.getHours():'0'+date.getHours()
				let minute = date.getMinutes()>9? date.getMinutes():'0'+ date.getMinutes()
				let second = date.getSeconds()>9?date.getSeconds():'0'+date.getSeconds()
				return `${hour}:${minute}`
			},
		}
	}
</script>

<style lang="scss" scoped>
	.product {
		width: 690rpx;
		padding-top: 24rpx;
		margin: 0 auto 0 auto;
		background-color: #FFF;
		// padding: 0 30rpx;
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		gap: 18rpx;
		box-sizing: border-box;
	}
	.box {
		width: 336rpx;
		min-height: 480rpx;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		background-color: #F7F7F7;
		position: relative;
		margin-bottom: 18rpx;
		.logo{
			position: absolute;
			bottom: 0;
			right: 0;
			width: 83rpx;
			height: 63rpx;
		}
		.product_img {
			width: 336rpx;
			height: 210rpx;
			// background: #C6CA53;
			border-radius: 20rpx;
			flex-shrink: 0;
			position: relative;
			image{
				width: 336rpx;
				height: 210rpx;
				border-radius: 20rpx;
			}
			.re{
				position: absolute;
				left:0;
				width: 82rpx;
				height: 70rpx;
			}
			.imgtit{
				width: 336rpx;
				height: 44rpx;
				background: linear-gradient(90deg, #F2C458 0%, #F9A95B 100%);
				border-radius: 0rpx 0rpx 20rpx 20rpx;
				position: absolute;
				bottom: 0;
				display: flex;
				align-items: center;
				font-size: 28rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #FFFFFF;
				image{
					width: 54rpx;
					height: 54rpx;
					box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(255,255,255,0.16);
					opacity: 1;
					// border: 1rpx solid #FFFFFF;
					border-radius: 100%;
					position: absolute;
					margin-top: -13rpx;
				}
				.namebox{
					margin-left: 60rpx;
					width: 276rpx;
					-webkit-line-clamp: 1;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}
		}

		.info {
			width: 308rpx;
			// display: flex;
			// flex-direction: column;
			justify-content: space-between;
			// gap: 22rpx;
			padding: 14rpx;
			height: 100%;

			.title {
				height: 90rpx;
				width: 308rpx;
				font-size: 32rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #222222;
				-webkit-line-clamp: 2;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			.text {
				font-size: 28rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #555555;
			}

			.price {
				display: flex;
				// justify-content: space-between;
				align-items: center;
				overflow: hidden;
				margin: 14rpx 0;

				.x_price {
					width: 68rpx;
					height: 38rpx;
					background: linear-gradient(180deg, #FCBB8C 0%, #FF8158 100%);
					border-radius: 4rpx 8rpx 8rpx 8rpx;
					font-size: 28rpx;
					font-family: Source Han Sans CN-Medium, Source Han Sans CN;
					font-weight: 500;
					color: #FFFFFF;
					text-align: center;
					line-height: 38rpx;
					margin-right: 20rpx;
				}

				.y_price {
					font-size: 28rpx;
					font-family: Source Han Sans CN-Regular, Source Han Sans CN;
					font-weight: 400;
					color: #555555;
				}
			}
			.but{
				width: 308rpx;
				height: 60rpx;
				background: #FF8A9B;
				border-radius: 32rpx ;
				font-size: 32rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #FFFFFF;
				opacity: 1;
				text-align: center;
				line-height: 60rpx;
				margin-top: 30rpx;
				-webkit-line-clamp: 1;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				overflow: hidden;
				text-overflow: ellipsis;
			}
		}

	}
</style>
